<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="../../../assets/docs.css" rel="stylesheet" type="text/css" media="screen" />
<title>MooTools 1.3 参考文档 - Types/Number</title>
</head>

<body>
  <div id="docs" class="doc">
    <div class="methods">
      <h4 class="menu-item"><a href="#Number">Number</a></h4>
      <div class="menu-item"><a href="#Number:Number-from">Number.from</a></div>
      <div class="menu-item"><a href="#Number:Number-random">Number.random</a></div>
      <div class="menu-item"><a href="#Number:limit">limit</a></div>
      <div class="menu-item"><a href="#Number:round">round</a></div>
      <div class="menu-item"><a href="#Number:times">times</a></div>
      <div class="menu-item"><a href="#Number:toFloat">toFloat</a></div>
      <div class="menu-item"><a href="#Number:toInt">toInt</a></div>
      <div class="menu-item"><a href="#Number-Math">Number.Math</a></div>
    </div>
    <div class="l-border r-border span-15 content">
      <h1 id="Number"><a href="#Number">类型: Number</a></h1>
      <p class="description">A collection of the Number Object methods and functions.</p>
      <h3>另参考:</h3>
      <ul>
        <li><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Number">MDC Number</a></li>
      </ul>
      <h3>提示:</h3>
      <p>Every Math method is mirrored in the Number object, both as prototype and generic.</p>
      <h2 id="Number:Number-from"><a href="#Number:Number-from">函数: Number.from</a></h2>
      <p class="description">Returns the passed parameter as a Number, or null if not a number.</p>
      <h3>语法: </h3>
      <pre class="javascript">Number.<span class="me1">from</span><span class="br0">(</span>arg<span class="br0">)</span>;
</pre>
      <h3>参数: </h3>
      <ol>
        <li>arg - (<em>mixed</em>) The argument to return as a number.</li>
      </ol>
      <h3>返回值: </h3>
      <ul>
        <li>(<em>number</em>) The argument as a number.</li>
        <li>(<em>null</em>) Returns null if the number cannot be converted.</li>
      </ul>
      <h3>示例: </h3>
      <pre class="javascript">Number.<span class="me1">from</span><span class="br0">(</span><span class="st0">'12'</span><span class="br0">)</span>       <span class="co1">// returns 12</span>
Number.<span class="me1">from</span><span class="br0">(</span><span class="st0">'hello'</span><span class="br0">)</span>    <span class="co1">// returns null</span>
</pre>
      <h2 id="Number:Number-random"><a href="#Number:Number-random">函数: Number.random</a></h2>
      <p class="description">Returns a random integer between the two passed in values.</p>
      <h3>语法: </h3>
      <pre class="javascript"><span class="kw2">var</span> random = Number.<span class="me1">random</span><span class="br0">(</span>min, max<span class="br0">)</span>;

</pre>
      <h3>参数: </h3>
      <ol>
        <li>min - (<em>number</em>) The minimum value (inclusive).</li>
        <li>max - (<em>number</em>) The maximum value (inclusive).</li>
      </ol>
      <h3>返回值: </h3>
      <ul>
        <li>(<em>number</em>) A random number between min and max.</li>
      </ul>
      <h3>示例: </h3>
      <pre class="javascript">Number.<span class="me1">random</span><span class="br0">(</span><span class="nu0">5</span>, <span class="nu0">20</span><span class="br0">)</span>; <span class="co1">// returns a random number between 5 and 20.</span>

</pre>
      <h2 id="Number:limit"><a href="#Number:limit">Number method: limit</a></h2>
      <p class="description">Limits this number between two bounds.</p>
      <h3>语法: </h3>
      <pre class="javascript">myNumber.<span class="me1">limit</span><span class="br0">(</span>min, max<span class="br0">)</span>;

</pre>
      <h3>参数: </h3>
      <ol>
        <li>min - (<em>number</em>) The minimum possible value.</li>
        <li>max - (<em>number</em>) The maximum possible value.</li>
      </ol>
      <h3>返回值: </h3>
      <ul>
        <li>(<em>number</em>) The number bounded between the given limits.</li>
      </ul>
      <h3>示例: </h3>
      <pre class="javascript"><span class="br0">(</span><span class="nu0">12</span><span class="br0">)</span>.<span class="me1">limit</span><span class="br0">(</span><span class="nu0">2</span>, <span class="nu0">6.5</span><span class="br0">)</span>;  <span class="co1">// returns 6.5</span>

<span class="br0">(</span><span class="nu0">-4</span><span class="br0">)</span>.<span class="me1">limit</span><span class="br0">(</span><span class="nu0">2</span>, <span class="nu0">6.5</span><span class="br0">)</span>;  <span class="co1">// returns 2</span>
<span class="br0">(</span><span class="nu0">4.3</span><span class="br0">)</span>.<span class="me1">limit</span><span class="br0">(</span><span class="nu0">2</span>, <span class="nu0">6.5</span><span class="br0">)</span>; <span class="co1">// returns 4.3</span>

</pre>
      <h2 id="Number:round"><a href="#Number:round">Number method: round</a></h2>
      <p class="description">Returns this number rounded to the specified precision.</p>
      <h3>语法: </h3>
      <pre class="javascript">myNumber.<span class="me1">round</span><span class="br0">(</span><span class="br0">[</span>precision<span class="br0">]</span><span class="br0">)</span>;

</pre>
      <h3>参数: </h3>
      <ol>
        <li>precision - (<em>number</em>, optional: defaults to 0) The number of digits after the decimal place.</li>
      </ol>
      <h3>返回值: </h3>
      <ul>
        <li>(number) The number, rounded.</li>
      </ul>
      <h3>提示:</h3>
      <ul>
        <li>Argument may also be negative.</li>
      </ul>
      <h3>示例: </h3>
      <pre class="javascript"><span class="br0">(</span><span class="nu0">12.45</span><span class="br0">)</span>.<span class="me1">round</span><span class="br0">(</span><span class="br0">)</span>   <span class="co1">// returns 12</span>

<span class="br0">(</span><span class="nu0">12.45</span><span class="br0">)</span>.<span class="me1">round</span><span class="br0">(</span><span class="nu0">1</span><span class="br0">)</span>  <span class="co1">// returns 12.5</span>
<span class="br0">(</span><span class="nu0">12.45</span><span class="br0">)</span>.<span class="me1">round</span><span class="br0">(</span><span class="nu0">-1</span><span class="br0">)</span> <span class="co1">// returns 10</span>

</pre>
      <h2 id="Number:times"><a href="#Number:times">Number method: times</a></h2>
      <p class="description">Executes the function passed in the specified number of times.</p>
      <h3>语法: </h3>
      <pre class="javascript">myNumber.<span class="me1">times</span><span class="br0">(</span>fn<span class="br0">[</span>, bind<span class="br0">]</span><span class="br0">)</span>;

</pre>
      <h3>参数: </h3>
      <ol>
        <li>fn   - (<em>function</em>) The function which should be executed on each iteration of the loop. This function is passed the current iteration's index.</li>
        <li>bind - (<em>object</em>, 可选) The object to use as 'this' in the function. For more information see <a href="../../../docs/core/Types/Function.html#Function:bind">函数:bind</a>.</li>
      </ol>
      <h3>示例: </h3>
      <pre class="javascript"><span class="br0">(</span><span class="nu0">4</span><span class="br0">)</span>.<span class="me1">times</span><span class="br0">(</span><span class="kw3">alert</span><span class="br0">)</span>; <span class="co1">// alerts "0", then "1", then "2", then "3".</span>
</pre>
      <h2 id="Number:toFloat"><a href="#Number:toFloat">Number method: toFloat</a></h2>
      <p class="description">Returns this number as a float. Useful because toFloat must work on both Strings and Numbers.</p>
      <h3>语法: </h3>
      <pre class="javascript">myNumber.<span class="me1">toFloat</span><span class="br0">(</span><span class="br0">)</span>;
</pre>
      <h3>返回值: </h3>
      <ul>
        <li>(<em>number</em>) The number as a float.</li>
      </ul>
      <h3>示例: </h3>
      <pre class="javascript"><span class="br0">(</span><span class="nu0">111</span><span class="br0">)</span>.<span class="me1">toFloat</span><span class="br0">(</span><span class="br0">)</span>; <span class="co1">// returns 111</span>

<span class="br0">(</span><span class="nu0">111.1</span><span class="br0">)</span>.<span class="me1">toFloat</span><span class="br0">(</span><span class="br0">)</span>; <span class="co1">// returns 111.1</span>
</pre>
      <h2 id="Number:toInt"><a href="#Number:toInt">Number method: toInt</a></h2>
      <p class="description">Returns this number as another number with the passed in base. Useful because toInt must work on both Strings and Numbers.</p>
      <h3>语法: </h3>
      <pre class="javascript">myNumber.<span class="me1">toInt</span><span class="br0">(</span><span class="br0">[</span>base<span class="br0">]</span><span class="br0">)</span>;
</pre>
      <h3>参数: </h3>
      <ol>
        <li>base - (<em>number</em>, optional: defaults to 10) The base to use.</li>
      </ol>
      <h3>返回值: </h3>
      <ul>
        <li>(<em>number</em>) A number with the base provided.</li>
      </ul>
      <h3>示例: </h3>
      <pre class="javascript"><span class="br0">(</span><span class="nu0">111</span><span class="br0">)</span>.<span class="me1">toInt</span><span class="br0">(</span><span class="br0">)</span>; <span class="co1">// returns 111</span>
<span class="br0">(</span><span class="nu0">111.1</span><span class="br0">)</span>.<span class="me1">toInt</span><span class="br0">(</span><span class="br0">)</span>; <span class="co1">// returns 111</span>

<span class="br0">(</span><span class="nu0">111</span><span class="br0">)</span>.<span class="me1">toInt</span><span class="br0">(</span><span class="nu0">2</span><span class="br0">)</span>; <span class="co1">// returns 7</span>
</pre>
      <h2 id="Number-Math"><a href="#Number-Math">Math Methods</a></h2>
      <p class="description">There are several methods available from the Math object that can be used as Number Methods.</p>
      <ul>
        <li>abs</li>
        <li>acos</li>
        <li>asin</li>
        <li>atan2</li>
        <li>ceil</li>
        <li>cos</li>
        <li>exp</li>
        <li>floor</li>
        <li>log</li>
        <li>max</li>
        <li>min</li>
        <li>pow</li>
        <li>sin</li>
        <li>sqrt</li>
        <li>tan</li>
      </ul>
      <h3>示例: </h3>
      <pre class="javascript"><span class="br0">(</span><span class="nu0">-1</span><span class="br0">)</span>.<span class="me1">abs</span><span class="br0">(</span><span class="br0">)</span>; <span class="co1">// returns 1</span>
<span class="br0">(</span><span class="nu0">3</span><span class="br0">)</span>.<span class="me1">pow</span><span class="br0">(</span><span class="nu0">4</span><span class="br0">)</span>; <span class="co1">// returns 81</span>

</pre>
    </div>
  </div>
<script type="text/javascript" src="../../../assets/mootools-core-1.3.js"></script>
<script type="text/javascript" src="../../../assets/mootools-more-smoothscroll.js"></script>
<script type="text/javascript" src="../../../assets/doc-assist.js"></script>
</body>
</html>
